<template>
  <view v-if="!isLoading" class="container">
    <u-navbar
      height="50"
      :border-bottom="false"
      title="订单核销"
      title-size="36"
      title-color="#333"
    ></u-navbar>
    <view v-if="order" class="card-area" style="margin-top: 40rpx">
      <!-- 商品列表 -->
      <view class="goods-list i-card">
        <view class="card-tl"> 产品详情</view>
        <view class="goods-item" v-for="(goods, idx) in order.items" :key="idx">
          <view class="goods-main" @click="handleTargetGoods(goods.goods_id)">
            <!-- 商品图片 -->
            <view class="goods-image">
              <image class="image" :src="goods.picUrl" mode="scaleToFill"></image>
            </view>
            <!-- 商品信息 -->
            <view class="goods-content">
              <view class="goods-title">
                <text class="twoline-hide">{{ goods.spuName }}</text>
              </view>
              <view class="goods-props clearfix">
                <text>{{ goods.properties[0].valueName }}</text>
              </view>
              <view class="goods-props">
                <text class="unit">¥</text>
                <text class="both">{{ (goods.payPrice * 0.01).toFixed(2) }} </text>
              </view>
            </view>
            <!-- 交易信息 -->
            <view class="goods-trade">
              <view class="goods-num">
                <text>×{{ goods.count }}</text>
              </view>
            </view>
          </view>
        </view>
      </view>

      <!-- 订单信息 -->
      <view class="order-info i-card">
        <view class="card-tl"> 订单信息</view>
        <view class="info-item">
          <view class="item-lable">交易单号</view>
          <view class="item-content">
            <text>{{ order.no }}</text>
            <view class="act-copy" @click="handleCopy(order.no)">
              <text>复制</text>
            </view>
          </view>
        </view>
        <view class="info-item">
          <view class="item-lable">下单时间</view>
          <view class="item-content">
            <text>{{ order.createTime }}</text>
          </view>
        </view>
        <view class="info-item">
          <view class="item-lable">卖家备注</view>
          <view class="item-content">
            <text>{{ order.remark || '--' }}</text>
          </view>
        </view>
        <view class="info-item">
          <view class="item-lable">买家留言</view>
          <view class="item-content">
            <text>{{ order.userRemark || '--' }}</text>
          </view>
        </view>
      </view>

      <!-- 结算信息 -->
      <view class="car-style">
        <view
          class="car-name"
          v-if="(order.status == 10 || order.status == 20) && order.deliveryType == 4"
          @click="onClerk"
          >确认核销
        </view>
        <view class="car-name disabled" v-else-if="order.status === 30">订单已完成 </view>
        <view class="car-name disabled" v-else>订单不可核销 </view>
      </view>
    </view>
    <view class="tips" v-else>
      <text>{{ msg }}</text>
    </view>
  </view>
  <view v-else class="tips">
    <text>数据加载中</text>
  </view>
</template>

<script>
export default {
  data() {
    return {
      verifyCode: '',
      isLoading: true,
      order: null,
      msg: ''
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    this.verifyCode = options.code || ''
  },
  onShow() {
    this.onRefreshPage()
  },
  methods: {
    // 刷新页面
    onRefreshPage() {
      // 获取页面数据
      this.getOrderDetail()
    },

    // 获取当前订单信息
    getOrderDetail(canReset = false) {
      const app = this
      app.isLoading = true
      app.$u
        .get('/app-api/trade/order/get-by-verify-code', {
          verifyCode: app.verifyCode
        })
        .then((res) => {
          app.isLoading = false
          if (res.code === 0) {
            app.order = res.data
            app.msg = ''
          } else {
            app.order = null
            app.msg = res.msg
          }
        })
        .catch(() => {
          app.isLoading = false
          app.msg = '出错了'
        })
    },
    handleCopy(value) {
      const app = this
      uni.setClipboardData({
        data: value,
        success: () => app.$u.toast('复制成功'),
        fail: ({ errMsg }) => app.$u.toast('复制失败 ' + errMsg)
      })
    },
    onClerk() {
      const app = this
      uni.showModal({
        title: '友情提示',
        content: '确认核销该笔订单吗？',
        success(o) {
          if (o.confirm) {
            app.$u
              .post('/app-api/trade/order/verify-by-verify-code?verifyCode=' + app.verifyCode, {})
              .then((result) => {
                // 显示成功信息
                if (result.code == 0) {
                  app.$u.toast('核销成功')
                  setTimeout(() => {
                    uni.navigateBack()
                  }, 1500)
                } else {
                  app.$u.toast(result.msg)
                }
              })
          }
        }
      })
    }
  }
}
</script>

<style>
page {
  background: #f4f4f4;
}
</style>
<style lang="scss" scoped>
.both {
  font-size: 30rpx;
  color: #121212;
}

.card-tl {
  font-size: 30rpx;
  color: #121212;
  padding-bottom: 24rpx;
}

// 商品图片
.goods-image {
  width: 180rpx;
  height: 180rpx;

  .image {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 8rpx;
  }
}

.cover {
  width: 120rpx;
  height: 120rpx;
}

.container {
  // 设置ios刘海屏底部横线安全区域
  padding-bottom: calc(constant(safe-area-inset-bottom) + 106rpx + 6rpx);
  padding-bottom: calc(env(safe-area-inset-bottom) + 206rpx + 6rpx);
}

.tips {
  width: 90%;
  height: 500rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

// 卡片区域
.card-area {
  // margin-top: -50rpx;
}

// 通栏卡片
.i-card {
  // background: #fff;
  padding: 24rpx 24rpx;
  width: 94%;
  box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  margin: 0 auto 20rpx auto;
  border-radius: 20rpx;
}

// 收货地址
.delivery-address {
  .link-man {
    line-height: 46rpx;
    color: #333;

    .name {
      margin-right: 10rpx;
    }
  }

  .address {
    margin-top: 12rpx;
    color: #999;
    font-size: 24rpx;

    .detail {
      margin-left: 6rpx;
    }
  }
}

// 物流公司
.express {
  display: flex;
  align-items: center;

  .main {
    flex: 1;
  }

  .info-item {
    display: flex;
    margin-bottom: 20rpx;

    &:last-child {
      margin-bottom: 0;
    }

    .item-lable {
      display: flex;
      align-items: center;
      font-size: 24rpx;
      color: #999;
      margin-right: 30rpx;
    }

    .item-content {
      flex: 1;
      display: flex;
      align-items: center;
      font-size: 26rpx;
      color: #333;

      .act-copy {
        margin-left: 20rpx;
        padding: 2rpx 20rpx;
        font-size: 22rpx;
        color: #666;
        border: 1rpx solid #c1c1c1;
        border-radius: 16rpx;
      }
    }
  }

  // 右侧箭头
  .right-arrow {
    margin-left: 16rpx;
    font-size: 26rpx;
  }
}

// 商品列表
.goods-list {
  // 商品项
  .goods-item {
    margin-bottom: 40rpx;

    &:last-child {
      margin-bottom: 0;
    }

    // 商品信息
    .goods-main {
      display: flex;
    }

    // 商品内容
    .goods-content {
      flex: 1;
      padding-left: 16rpx;
      padding-top: 16rpx;

      .goods-title {
        font-size: 26rpx;
        max-height: 76rpx;
      }

      .goods-props {
        margin-top: 14rpx;
        // color: #ababab;
        font-size: 24rpx;
        overflow: hidden;

        .goods-props-item {
          padding: 4rpx 16rpx;
          border-radius: 12rpx;
          background-color: #fcfcfc;
        }
      }
    }

    // 交易信息
    .goods-trade {
      padding-top: 16rpx;
      width: 150rpx;
      text-align: right;
      font-size: 26rpx;

      .goods-price {
        vertical-align: bottom;
        margin-bottom: 16rpx;

        .unit {
          margin-right: -2rpx;
          font-size: 24rpx;
        }
      }
    }

    // 商品售后
    .goods-refund {
      display: flex;
      justify-content: flex-end;

      .stata-text {
        font-size: 24rpx;
        color: #999;
      }

      .action-btn {
        border-radius: 28rpx;
        padding: 8rpx 26rpx;
        font-size: 24rpx;
        color: #383838;
        border: 1rpx solid #a8a8a8;
      }
    }
  }
}

// 订单信息
.order-info {
  .info-item {
    display: flex;
    margin-bottom: 24rpx;

    &:last-child {
      margin-bottom: 0;
    }

    .item-lable {
      display: flex;
      align-items: center;
      font-size: 24rpx;
      color: #999;
      margin-right: 30rpx;
    }

    .item-content {
      flex: 1;
      display: flex;
      align-items: center;
      font-size: 26rpx;
      color: #333;

      .act-copy {
        margin-left: 20rpx;
        padding: 2rpx 20rpx;
        font-size: 22rpx;
        color: #666;
        border: 1rpx solid #c1c1c1;
        border-radius: 16rpx;
      }
    }
  }
}

// 交易信息
.trade-info {
  .info-item {
    display: flex;
    margin-bottom: 24rpx;

    .item-lable {
      font-size: 24rpx;
      color: #999;
      margin-right: 24rpx;
    }

    .item-content {
      flex: 1;
      font-size: 26rpx;
      color: #333;
      text-align: right;
    }
  }

  .divider {
    height: 1rpx;
    background: #f1f1f1;
    margin-bottom: 24rpx;
  }

  .trade-total {
    display: flex;
    justify-content: flex-end;

    .lable {
      line-height: 49rpx;
    }

    .goods-price {
      margin-left: 12rpx;
      vertical-align: bottom;

      .unit {
        margin-right: -2rpx;
        font-size: 24rpx;
      }

      .value {
        font-size: 34rpx;
        line-height: 40rpx;
      }
    }
  }
}

.clerk-info {
  background: #e6e6e6;
  padding: 0;

  .top {
    border-radius: 20rpx;
    background-color: #fff;
    padding: 24rpx;
  }

  .clerk-detail {
    width: 100%;

    .goods-image {
      width: 192rpx;
      height: 192rpx;
    }

    .con {
      flex: 1;
      font-size: 26rpx;
      color: #454545;
      margin-right: 40rpx;
    }
  }

  .clerk-bt {
    // background: #E6E6E6;
    padding: 24rpx;

    .bt {
      width: 110rpx;
      height: 54rpx;
      border-radius: 27rpx;
      border: 1rpx solid #999999;
      font-size: 28rpx;
      color: #121212;
      line-height: 52rpx;
      text-align: center;
    }

    .more {
      width: 36rpx;
      height: 8rpx;
      margin-right: 104rpx;
      margin-left: 30rpx;
    }

    .qrcode {
      width: 130rpx;
      background: #e30081;
      color: #ffffff;
      border: none;
    }
  }
}

// 底部操作栏
.footer-fixed {
  position: fixed;
  bottom: var(--window-bottom);
  left: 0;
  right: 0;
  z-index: 11;
  box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  background: #fff;

  // 设置ios刘海屏底部横线安全区域
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);

  .btn-wrapper {
    height: 106rpx;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 30rpx;
  }

  .btn-item {
    min-width: 180rpx;
    border-radius: 30rpx;
    padding: 12rpx 26rpx;
    font-size: 28rpx;
    color: #383838;
    text-align: center;
    border: 1rpx solid #a8a8a8;
    margin-left: 24rpx;

    &.active {
      border: none;
      // background: linear-gradient(to right, $main-bg, $main-bg2);
      // color: $main-text;
    }
  }
}

.car-name {
  border-radius: 35rpx;
  border: 2px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: auto;
  height: 80rpx;
  background: #069090;
  position: absolute;
  bottom: 40rpx;
  left: 4vw;
  width: calc(100% - 8vw);
  text-align: center;
  font-weight: 400;
  font-size: 28rpx;
  color: #ffffff;
  padding-left: 4rpx;
}

.disabled {
  background: #80808069;
}
</style>
